<script setup>

import { ref } from 'vue'
import {
  selectDeviceListService,
  handleDeviceListService
} from '@/api/StudentCourseDevice.js'
const dialogVisible = ref(false)


const total = ref(0)
const params = ref({
  courseName:'',
  pageNum:1,
  pageSize:5
})

const studentCourseDeviceList = ref([])
const studentCourseDeviceVo = ref({
    id:'',
    courseName:'',
    userName:'',
    deviceDesc:'',
    teacherDesc:'',
    handleStatus:'',
    createTime:'',
    createTimeStr:'',
    handleStatusStr:''
})

const handleCurrentChange = (page)=>{
  params.value.pageNum = page
  selectDeviceList()
}
const selectDeviceList = async ()=>{
  const res = await selectDeviceListService(params.value)
  studentCourseDeviceList.value = res.data.data
  total.value = res.data.total
}
selectDeviceList()

const deviceRes = ref({
  id:'',
  teacherDesc:''
})

const handleClick = (row) => {
  deviceRes.value.id = row.id
  dialogVisible.value = !dialogVisible.value
}

const confirmDeviceBtn = async ()=> {
  await handleDeviceListService(deviceRes.value)
  ElMessage.success('成功！')
  dialogVisible.value = !dialogVisible.value
  deviceRes.value = {}
  selectDeviceList()
}

const search = () => {
  selectDeviceList()
}
</script>

<template>
  <div>
    <div class="cus-header">
        <el-card>
          <div style="display: flex;justify-content: space-between;">
            <div class="search">
                <div>
                    课程：
                    <el-input v-model="params.courseName" style="width: 240px" placeholder="请输入课程名称" />
                </div>
              
                <div style="margin-left: 20px;">
                    <el-button @click="search" style="width: 80px;" type="primary">搜索</el-button>
                </div>
            </div>
            <div class="insert">
              <el-button @click="search" style="width: 80px;" type="primary">新增</el-button>
            </div>
          </div>
            
            
        </el-card>
    </div>
    <div class="cus-body">
        <el-card style="min-height: 650px;">
            <el-table :data="studentCourseDeviceList" style="width: 100%">
                <el-table-column fixed prop="id" label="意见编号" width="100" />
                <el-table-column prop="courseName" label="课程名称" width="120" />
                <el-table-column prop="userName" label="学生名称" width="120" />
                <el-table-column prop="handleStatusStr" label="处理状态" width="120" />
                <el-table-column prop="createTimeStr" label="创建时间" width="150" />
                <el-table-column prop="teacherDesc" label="教师结果" width="120" />
                <el-table-column prop="deviceDesc" label="意见描述" width="600" />
                <el-table-column fixed="right" label="操作" min-width="120">
                <template #default = "{row}">
                    <el-button link type="primary" size="small" @click="handleClick(row)">
                        处理
                    </el-button>
                </template>
                </el-table-column>
            </el-table>
            <div style="margin-top: 20px;">
              <el-pagination
              v-model:current-page="params.pageNum"
              v-model:page-size="params.pageSize"
              :background="true"
              layout="jumper,prev, pager, next,total"
              :total=total
              @current-change="handleCurrentChange"
              style="justify-content: end;"
            /></div>
        </el-card>
    </div>
  </div>

  <el-dialog
    v-model="dialogVisible"
    title="处理"
    width="500"
    :before-close="handleClose"
  >
    意见反馈：<el-input v-model="deviceRes.teacherDesc" style="width: 240px" placeholder="请输入" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmDeviceBtn">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>


<style lang="scss" scoped>
    .flex-row{
        display: flex;
        flex-direction: row;
    }
    .cus-header{
        .search{
            display: flex;
            flex-direction: row;
        }
    }
    .cus-body{
        margin-top: 15px;
    }
</style>